/**************************************************************
 *   File:	ScreenQuad.h
 * Author:	Andrew Thorpe
 *  Brief:	A base class for all on screen elements
 **************************************************************/
#ifndef _FOSSIL_SCREENQUAD_H
#define _FOSSIL_SCREENQUAD_H

#include "Functions.h"

namespace Fossil
{
	//Forward declarations
	class Texture;

	class ScreenQuad
	{
	public:
		ScreenQuad(void);
		ScreenQuad(const ScreenQuad& rhs);
		virtual ~ScreenQuad(void);
		ScreenQuad& operator=(const ScreenQuad& rhs);

		virtual void Render(float width, float height, float depth) const;

		inline void SetX(float x) { m_X = Cap(x, 0.0f, 1.0f); }
		inline void SetY(float y) { m_Y = Cap(y, 0.0f, 1.0f); }
		inline void SetWidth(float width) { m_Width = Cap(width, 0.0f, 1.0f); }
		inline void SetHeight(float height) { m_Height = Cap(height, 0.0f, 1.0f); }

		inline float GetX() const { return m_X; }
		inline float GetY() const { return m_Y; }
		inline float GetWidth() const { return m_Width; }
		inline float GetHeight() const { return m_Height; }

		inline ScreenQuad* Parent() { return m_pParent; }
		inline ScreenQuad* Child()	{ return m_pFirstChild; }
		inline ScreenQuad* Next()	{ return m_pNextSibling; }

		inline void SetPos(float x, float y) { SetX(x); SetY(y); }
		inline void SetSize(float width, float height) { SetWidth(width); SetHeight(height); }

		/*void AttachTo(ScreenQuad* pParent);
		void AttachChild(ScreenQuad* pChild);
		void AddSibling(ScreenQuad* pChild);

		void DetachFromParent();
		void DetachChild(ScreenQuad* pChild);*/
		
		//! Link methods
		ScreenQuad* GetParent() const { return m_pParent; }
		ScreenQuad* GetFirstChild() const { return m_pFirstChild; }
		ScreenQuad* GetNextSibling() const { return m_pNextSibling; }
		//! Family tree
		bool IsAncestorOf(ScreenQuad* pScreenQuad);

		virtual	void SetParent(ScreenQuad* pParent);

		// Attached children are linked to the last child
		virtual ScreenQuad* AttachChild(ScreenQuad* pScreenQuad);

		//! Entity functionality, destroy this object & it's children
		virtual void Destroy();

	protected:

		// Link this object to the start of the tree (root)
		virtual void AddScreenQuadToParent(ScreenQuad* pParent);
		// Link this object to the end of the tree (leaf)
		virtual void AttachScreenQuadToParent(ScreenQuad* pParent);
		// Remove this object from the tree
		virtual void RemoveScreenQuadFromParent();
		// Destroy all of the children in this hierarchy
		virtual void DeleteAllScreenQuadChildren();

	private:
		float m_X, m_Y, m_Width, m_Height;

		ScreenQuad* m_pParent;
		ScreenQuad* m_pFirstChild;
		ScreenQuad* m_pNextSibling;

		Texture*	m_pTexture;

		friend class Renderer;
	};
};

#endif//_FOSSIL_SCREENQUAD_H
